# echo server 回显服务
# 只响应一个客户端
import socket
import select

host = "localhost"
port = 6677
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.bind((host, port))
    sock.listen(1)
    conn, addr = sock.accept()
    with conn:
        print("connected by", conn)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            print("recv:", conn.getpeername(), "data:", data)
            conn.sendall(data)
